package com.will.rpc;

import com.will.client.NettyClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.AbstractFactoryBean;


import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author 杨明智
 * @version:1.0
 * @create 2019年01月11日 5:13 PM
 * @description RPC工厂类
 **/
public class RPCProxyFactoryBean extends AbstractFactoryBean<Object> implements InvocationHandler {

    private Logger logger = LoggerFactory.getLogger(RPCProxyFactoryBean.class);
    private Class interfaceClass;
    private NettyClient nettyClient;

    @Override
    public Class<?> getObjectType() {
        return interfaceClass;
    }

    @Override
    protected Object createInstance() throws Exception {
        logger.info("[代理工厂] 初始化代理Bean : {}", interfaceClass);
        return Proxy.newProxyInstance(interfaceClass.getClassLoader(),new Class[]{interfaceClass},this);
    }

    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {

        return null;
    }

    public void setInterfaceClass(Class interfaceClass) {
        this.interfaceClass = interfaceClass;
    }

    public void setNettyClient(NettyClient nettyClient) {
        this.nettyClient = nettyClient;
    }
}
